<?php
/**
* 显示主题页面
* $Id: thread.php 153 2010-05-05 22:22:48Z bwanglei $
*/

include_once(dirname(__FILE__).'/init.php');

// 发布新帖子
if ($_SERVER['REQUEST_METHOD']=='POST') {
	if (apf_is_login()) {
		$content_new_article = $_POST['content_article'];
		$thread_id = $_POST['thread_id'];
		$username_article = $_SESSION['username'];
		$query_insert_article = "insert into ".DB_PREFIX."article (username,content,thread_id,time_date) values ('".$username_article."','".$content_new_article."',".$thread_id.",".time().")";
		$mysql_conn->query($query_insert_article);
		apf_redirect(0,$_GET['source'].'#'.$mysql_conn->insert_id);
	} else {
		apf_msg('未登录！', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
	}
}

// 取得线索ID号
$thread_id = $_GET['t_id'];
if ((isset($thread_id)) and ($thread_id!=Null)) {
	$thread_id = intval($thread_id);
} else {
	apf_redirect(0,$apf_settings['base_url'].'message.php?m=错误的参数');
	exit;
}

// 阅读数加一
$now_read_count = apf_get_read_count_thread($thread_id);
apf_add_read_count_thread($thread_id,$now_read_count);

// 取得页面号
@$num_page = $_GET['b'];
$count_page = apf_count_page_thread($apf_settings['count_articles_thread'],$thread_id,$mysql_conn);
if (isset($num_page) and $num_page<=$count_page and $num_page>0) {
	$num_page = ceil($num_page);
} else if ($num_page <= 0) {
	$num_page = 1;
} else if ($num_page > $count_page) {
	$num_page = $count_page;
}

// 页面总数
$page_count = apf_count_page_thread($apf_settings['count_articles_thread'],$thread_id,$mysql_conn);

// 调用函数返回线索下的所有文章数组
$articles_thread = apf_get_thread($mysql_conn,$thread_id,$num_page,$apf_settings);
include_once(BASE_PATH.TEMP_DIR.'/thread.php');
?>
